// This is the main DLL file.

using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;

namespace Silverlight
{
    namespace Hosting
    {
        namespace Private
        {
            public ref class AxHostContainer : AxHost
            {
            private:
                bool m_windowless;

            public:
                AxHostContainer(String^ clsid, bool windowless)
                    : AxHost(clsid)
                {
                    m_windowless = windowless;
                }

                #define SET_PROP(prop, val) \
                    if (m_windowless) Control::prop = val; \
                        else AxHost::prop = val;

                #define GET_PROP(prop) \
                    if (m_windowless) return Control::prop; \
                        else return AxHost::prop;

                #define VOID_FUNC_CALL(func) \
                    if (m_windowless) { Control::func; } \
                        else { AxHost::func; }

                #define FUNC_CALL(func) \
                    return (m_windowless ? Control::func : AxHost::func);


                virtual property String^ Text
                {
                    String^ get() override
                    {
                        GET_PROP(Text);

                    }
                    void set(String^ text) override
                    {
                        SET_PROP(Text, text);
                    }
                }

                virtual property System::ComponentModel::ISite^ Site
                {
                    System::ComponentModel::ISite^ get() override
                    {
                        GET_PROP(Site);
                    }
                    void set(System::ComponentModel::ISite^ site) override
                    {
                        SET_PROP(Site, site );
                    }
                }

                virtual bool PreProcessMessage(Message% m) override
                {
                    FUNC_CALL(PreProcessMessage(m));
                }

                virtual String^ ToString() override
                {
                    FUNC_CALL(ToString());
                }

            protected:

                virtual property System::Windows::Forms::CreateParams^ CreateParams
                {
                    System::Windows::Forms::CreateParams^ get() override
                    {
                        GET_PROP(CreateParams);
                    }
                }

                virtual property System::Drawing::Size DefaultSize
                {
                    System::Drawing::Size get() override
                    {
                        GET_PROP(DefaultSize);
                    }
                }

                virtual void OnFontChanged(EventArgs^ e) override
                {
                    VOID_FUNC_CALL(OnFontChanged(e));
                }

                virtual void OnForeColorChanged(EventArgs^ e) override
                {
                    VOID_FUNC_CALL(OnForeColorChanged(e));
                }

                virtual void OnBackColorChanged(EventArgs^ e) override
                {
                    VOID_FUNC_CALL(OnBackColorChanged(e));
                }

                virtual void OnLostFocus(EventArgs^ e) override
                {
                    VOID_FUNC_CALL(OnLostFocus(e));
                }

                virtual void CreateHandle() override
                {
                    VOID_FUNC_CALL(CreateHandle());
                }

                virtual Rectangle GetScaledBounds(Rectangle bounds, SizeF factor, BoundsSpecified specified) override
                {
                    FUNC_CALL(GetScaledBounds(bounds, factor, specified));
                }

                virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) override
                {
                    VOID_FUNC_CALL(SetBoundsCore(x, y, width, height, specified));
                }

                virtual void DestroyHandle() override
                {
                    VOID_FUNC_CALL(DestroyHandle());
                }

                virtual void SetVisibleCore(bool value) override
                {
                    VOID_FUNC_CALL(SetVisibleCore(value));
                }

                virtual bool IsInputChar(Char charCode) override
                {
                    FUNC_CALL(IsInputChar(charCode));
                }

                virtual bool ProcessDialogKey(Keys keyData) override
                {
                    FUNC_CALL(ProcessDialogKey(keyData));
                }

                virtual void WndProc(Message% m) override
                {
                    VOID_FUNC_CALL(WndProc(m));
                }

                virtual void OnHandleCreated(EventArgs^ e) override
                {
                    VOID_FUNC_CALL(OnHandleCreated(e));
                }
            };
        }	
    }
}
